<?php

namespace Home\Model;

use Think\Model;

class EreaModel extends Model
{
    public function __construct()
    {
        parent::__construct('area');
    }

    /**
     * 取得地区表数据
     */
    public function area_data($condition = array())
    {
        $area_data = $this->where($condition)->select();
        // 查库
        $data = array();
        foreach ((array)$area_data as $a) {
            $data['name'][$a['area_id']] = $a['area_name'];
            $data['parent'][$a['area_id']] = $a['area_parent_id'];
            $data['children'][$a['area_parent_id']][] = $a['area_id'];
            if ($a['area_deep'] == 1) {
                $data['region'][$a['area_region']][] = $a['area_id'];
            }

        }

        $arr = array();
        foreach ($data['children'] as $k => $v) {
            foreach ($v as $vv) {
                $arr[$k][] = array($vv, $data['name'][$vv]);
            }
        }

        return $arr;

    }


}